//
//  RIOTabBarController.swift
//  RIOWeiBo
//
//  Created by Rio on 16/4/6.
//  Copyright © 2016年 RIO. All rights reserved.
//

import UIKit

class RIOTabBarController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        
        let RioTabBar = RIOTabBar()
        
        RioTabBar.plusButton.addTarget(self, action: #selector(RIOTabBarController.plusButtonDidClick), forControlEvents: .TouchUpInside)
        /**
         使用kvc用自定义的tabbar替换系统自带的tabbar
         
         - parameter forKey: tabBar
         */
        setValue(RioTabBar, forKey: "tabBar")
        
        
        addChildViewControllers()
        
    }

    /**
     private修饰后方法只有在当前文件才能访问
     */
    private func addChildViewControllers(){
        setChildControllers(childController:RIOHomeController(), titleName: "首页", imageName: "tabbar_home")
        setChildControllers(childController: RIOMassageController(), titleName: "消息", imageName: "tabbar_message_center")
        setChildControllers(childController:RIODiscoverController(), titleName: "发现", imageName: "tabbar_discover")
        setChildControllers(childController:RIOProfileController(), titleName: "我", imageName: "tabbar_profile")
        
    }
   
    /**
     添加每个子视图控制器
     
     - parameter className: 子视图
     - parameter titleName: 子视图控制器名字
     - parameter imageName: 图片名称
     */
    func setChildControllers(childController className:UIViewController, titleName:String , imageName:String) {
        
//        className.tabBarItem.title = titleName
//        
//        className.navigationItem.title = titleName
        /**
         当各种title一样时,直接.title就可以了
         */
        className.title = titleName
        
        className.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.orangeColor()], forState: .Selected)
        className.tabBarItem.image = UIImage (named: imageName)
        className.tabBarItem.selectedImage = UIImage (named:imageName+"_selected")?.imageWithRenderingMode(.AlwaysOriginal)
        
        /// 创建一个navgationcontroller,rootviewcontroller是给定的控制器
        let nav = UINavigationController (rootViewController: className)
        
        addChildViewController(nav)
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


    // MARK: - 加号按键点击方法
    /**
     加号按键点击方法
     */
    @objc private func plusButtonDidClick(){
        
    }

}
